﻿using System;
using System.Data;
using System.Text;
namespace WPFExcelReport.Helpers
{
    /// <summary>
    /// VisualHelper convert the given visual content as an image
    /// </summary>
    public static partial class Helper
    {
        public static string GetGB2312Value(string strSource)
        {
            byte[] b;
            string filevalue = "";
            b = Encoding.GetEncoding("ISO-8859-1").GetBytes(strSource);
            filevalue = Encoding.GetEncoding("gb2312").GetString(b);
            return filevalue;
        }
        public static string GetGB2312Value(DataRow dwTemp, string nmField)
        {
            byte[] b;
            string filevalue = "";
            b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[nmField].ToString());
            filevalue = Encoding.GetEncoding("gb2312").GetString(b);
            return filevalue;
        }
        public static string GetGB2312Value(string strSource, string nmField)
        {
            byte[] b;
            string filevalue = "";
            b = Encoding.GetEncoding("ISO-8859-1").GetBytes(strSource);
            filevalue = Encoding.GetEncoding("gb2312").GetString(b);
            return filevalue;
        }
        public static string Right(string str, int num)
        {
            try
            {
                int leng = str.Length;
                str = str.Substring(leng - num, num);
            }
            catch (Exception ex)
            {
            }
            return str;
        }
        public static string Left(string str, int num)
        { 
            int leng = str.Length;
            str = str + "                                                                                ";
            str = str.Substring(0, num);

            return str;
        }
    }
}
